package com.traffic.managent.jedis.running;

import org.apache.log4j.Logger;

import com.traffic.managent.service.order.bean.OrderBean;

/**
 * 回调 类名称: OrderCallbacksExecutor 类描述: 回调
 */
public class OrderCallbacksExecutor implements OrderUtils {

	private static Logger logger = Logger.getLogger(OrderCallbacksExecutor.class);

	public final static OrderCallbacksExecutor service = new OrderCallbacksExecutor();

	public void setOrder(OrderBean order) {
		String url = order.getCallbackUrl();
		if (url != null && !"".equals(url)) {
			boolean isUrl = checkUrl(url);
			if (isUrl) {
				logger.info("set invoke data url[" + url + "] to redis,tel= " + order.getPhoneNo());
			} else {
				logger.info("back invoke url[" + url + "] is invalid..tel=" + order.getPhoneNo());
			}
		}
	}

	public static boolean checkUrl(String url) {
		String regEx = "^(http|https|ftp)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-"
				+ "Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{"
				+ "2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}"
				+ "[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|"
				+ "[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-"
				+ "4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0"
				+ "-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/"
				+ "[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&%\\$\\=~_\\-@]*)*$";
		return url.matches(regEx);
	}
}
